package com.lcz.demo.customerorder;

import com.lcz.demo.DemoApplication;
import com.lcz.demo.exception.NotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Service
//声明bean的注解
public class CustomerService {
    private final Logger logger= LoggerFactory.getLogger(CustomerService.class);
    private final CustomerDAO customerDAO;
@Autowired
    public CustomerService(CustomerDAO customerDAO) {
        this.customerDAO = customerDAO;
    }
//找到数据库中全部数据
    List<Customer> getCustomers(){
        logger.info("get Customer call");
        return customerDAO.findAll();
    }
    Customer getcustomer (Long id){
        return customerDAO
                .findById(id.intValue())




                .orElseThrow(()->{
        NotFoundException notFoundException=new NotFoundException("customer"+id+"无法找到错误");
        logger.error("error getCustomer{}"+id,notFoundException);
        return notFoundException;
    });
    }
}

